const path = require('path');
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = function (ev) {
  return {
    // entry: './src/index.js',
    entry: {
      index: './src/index.js',
      entry: './src/entry.js'
    },
    output: {
      //多文件输出([name] entry中得文件名)
      filename: '[name].[chunkhash].js',
      path: path.resolve(__dirname, 'public')
    },
    //开发环境development 生产环境production
    mode: 'development',
    devServer: {
      contentBase: require('path').join(__dirname, "dist"),
      compress: true,
      port: 8088,
      host: "192.168.1.2",
    },
    module: {
      rules: [{
        test: /\.css$/,
        exclude: /node_modules/,
        use: [
          'style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.(png|svg|jpg|gif)$/,
        exclude: /node_modules/,
        use: [{
          loader: 'file-loader'
        }]
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/,
        exclude: /node_modules/,
        use: [
          'file-loader'
        ]
      }]
    },
    plugins: [
      new CleanWebpackPlugin(),
      new HtmlWebpackPlugin({
        title: 'Output Management',
        template: 'index.html'
      }),
      // new CopyWebpackPlugin([
      //   { from: 'src/assets/', to: path.resolve(__dirname, 'dist') }
      // ])
    ],
    resolve: {
      //配置别名，在项目中可缩减引用路径
      alias: {
        "@": path.resolve('src'),
      }
    }
  }
};